package cn.mux.jdk8;

import java.util.Collection;
import java.util.HashSet;
import java.util.function.Predicate;

import sun.text.resources.cldr.or.FormatData_or;


public class PredicateTest {
	public static void main(String[] args) {
		Collection<String> books = new HashSet<>();
		books.add("轻量级java EE 企业级应用");
		books.add("疯狂java讲义");
		books.add("疯狂ios讲义");
		books.add("疯狂ajax讲义");
		books.add("疯狂android讲义");
		//books.removeIf(str->((String)str).length()<10);
		System.out.println(books);
		//统计书名中出现疯狂字符串的图书数量
		System.out.println(calAll(books, str->((String)str).contains("疯狂")));
		//统计书名中出现java字符串的图书数量
		System.out.println(calAll(books, str->((String)str).contains("java")));
		//统计书名大于10图书数量
		System.out.println(calAll(books, str->((String)str).length()>10));
		
		
		
		//jdk 8 stream 
	}
	
	public static int calAll(Collection<String> books,Predicate predicate){
		
		int total =0;
		for(Object obj : books){
			if(predicate.test(obj)){
				total++;
			}
		}
		return total;
	}
}
